<template lang="pug">
  <div>
    el-dialog(
      :visible.sync="auditShow"
      width="560px"
      @open="beforeOpen"
      :before-close="handleClose"
      :close-on-click-modal="false"
    )
      .modal-title(slot="title") {{ audit.title }}
      el-form(
        :model="form"
        size="small"
        :rules="rules"
        ref="memberForm"
        label-width="100px"
        )
        el-form-item(label="请输入审核意见:" :label-width="formLabelWidth" prop="companyList" )
          h5() 请输入审核意见:123456789
          //- .auditOpinion {{form.auditOpinion}} 
      div(slot="footer" class="dialog-footer")
        el-button(@click="handleClose") 取消
        el-button(type="primary" @click="save") 确 定
  </div>
</template>

<script>
import { getSupplierBrandInformation,batchAudit } from 'api'
export default {
  name: 'auditDialog',
  props:{
    auditShow: Boolean,
    item: Object,
    audit: {},
  },
  data() {
    return {
      title:'',
      form: {
        name: '',
        trademarkRegistrationNumber: '',
        brandCompany:'',
        isImport: '',
        companyList: [],
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入品牌名称', trigger: 'blur' }
        ],
        trademarkRegistrationNumber: [
          { required: true, message: '请输入商标注册号', trigger: 'blur' },
        ],
        brandCompany: [
          { required: true, message: '请输入品牌公司', trigger: 'blur' }
        ],
        isImport: [
          { required: true, message: '请选择产地', trigger: 'change' }
        ]
      },
      formLabelWidth: '100px',
      restaurants:[]
    }
  },

  methods:{
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handleClose () {
      this.$emit('close')
      // this.$refs.hiddenUpload.clearFiles()
    },

    async submit () {
      if (!this.logoFiles.length && !this.form.logoUrl) {
        this.$message.error('请上传品牌logo！')
        return
      }
      if (this.logoFiles.length) {
        const logoFile = await this.fileUpload(this.logoFiles[0].raw)
        this.form.logo = logoFile.fileId
        this.form.logoUrl = logoFile.fileUrl
      }
      try {
        let query = { ...this.form }
        // console.log(this.form)
        await this.$axios.post(addOrUpdateBrand,  { ...query } )
        this.$message.success('保存成功！')
        this.$emit('confirm')
      } catch (err) {
        console.log(err)
        this.$message.error(err.message || err.ResultSet.errors)
      }
    },
    save () {
      this.$refs.memberForm.validate((valid) => {
        console.log(valid)
        if (valid) this.submit()
      })
    },
   async auditFailer(){
    const { ResultSet } = await this.$axios.post(batchAudit, {supplierBrandIdList:this.item.supplierBrandId })    
    this.audit.status = ResultSet.userData.reviewStatus
    console.log(this.audit.status)
    this.$emit("failer")
    },
    async beforeOpen () {
      console.log(this.item.supplierBrandId) 
        const { ResultSet } = await this.$axios.post(getSupplierBrandInformation, { supplierBrandId:this.item.supplierBrandId })    
        this.form = { ...ResultSet.userData.supplierBrandInformation }
        // this.title= audit.title
    },

    delFiles (key, index) {
      this[key].splice(index, 1)
    },
    delLogoUrl () {
      this.form.logo = ''
      this.form.logoUrl = ''
    },
  },
  
  // beforeRouteEnter (to, from, next) {
  //   // ...
  //   next(vm => {
  //     vm.initRestaurants()
  //     if (to.params.id) {
  //       vm.title = '品牌编辑'  
  //       vm.getBrandLibraryList()            
  //     } else {
  //       vm.title = '品牌添加'
  //     }
  //   })
  // },
}
</script>
<style type="text/css" lang="scss">
.upload-demo {
  .el-upload--picture-card {
    width: 98px;
    height: 98px;
    line-height: 1;
  }
  .el-upload-btn-txt {
    margin-top: 15px;
  }
}

</style>
<style lang="scss" scoped>
  .modal-title{
    font-size:16px;
    font-weight:bold;
  }
  .el-dialog__header{
    border-bottom:1px solid #ccc;
  }
  .el-form-bd {
    margin-top: 15px;
    display: flex;
    // margin-left:100px;
  }
  .el-form-info {
    font-size: 14px;
    color: #AFAFAF;
  }
  .el-form-file {
    display: flex;
    align-items: center;
    .el-form-img {
      position: relative;
      width: 96px;
      height: 96px;
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
      margin-left: 16px;
      border-radius: 4px;
    .icon-chakan {
      position: absolute;
      top: 50%;
      right: 21%;
      transform: translate(50%, -50%);
      cursor: pointer;
      color: #fff;
    }
    .icon-shanchu1{
      position: absolute;
      top: 50%;
      left: 21%;
      transform: translate(50%, -50%);
      cursor: pointer;
      color: #fff;
    }
  }
  .el-bgcover{
    position:absolute;
    top:0;
    left:0;
    width:96px;
    height:96px;
    background-color:#333;
    opacity: 0.7;
    border-radius:4px;
    z-index:1000;
    cursor: pointer;
  }
}
.el-agency{
  border:1px solid #DCDFE6;
  padding:8px 15px;
  border-radius: 4px;
  min-height:32px;
  p{
    line-height:23px;
  }
}
.el-upload--picture-card i{
  font-size:14px;
}
.el-upload-btn {
  width: 96px;
  height: 96px;
  background: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #B2B4C7;
  .iconfont {
    font-size: 20px;
    font-weight: bold;
  }
  .el-upload-btn-txt {
    font-size: 14px;
  }
}
.el-upload--picture-card{
  line-height:32px;
}
.el-upload{
  width:96px;
  height:96px;
}

</style>